import axios from "axios";
import config from "@/util/config.js";

//创建一个axios的对象
const workshopAPI = {
    mdBaseUrl: config.mdUrl+"/md",
    mdProMat: "/workshop",
    timeout: 5000,

    //分页查询车间信息
    getWorkshopsByName(param, callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/query", {
            params: param
        }).then((res) => {
            callback(res.data);
        })
    },
    //添加车间信息
    addWorkshop(param, callback) {
        axios.request({
            url: this.mdBaseUrl + this.mdProMat + "/add",
            method: "post",
            data: param,
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            }
        }).then((res) => {
            callback(res.data);
        })
    },
    //删除车间信息
    deleteWorkshop(param, callback) {
        axios.request({
            url: `${this.mdBaseUrl}${this.mdProMat}/${param.id}/${param.status}`,
            method: "delete",
        }).then((res) => {
            callback(res.data);
        })
    },
    //修改车间信息
    updateWorkshop(param, callback) {
        axios.request({
            url: this.mdBaseUrl + this.mdProMat + "/update",
            method: "put",
            data: JSON.stringify(param),
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            }
        }).then((res) => {
            callback(res.data);
        })
    },
    //获取总条数
    getCount(callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/count").then((res) => {
            callback(res.data);
        })
    },
    //获取所有车间信息
    getMdWorkshops(callback){
        axios.get(this.mdBaseUrl + this.mdProMat + "/queryAll").then((res) => {
            callback(res.data);
        })
    }
};
export default workshopAPI;